package com.yoomiito.app.share.presenter;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.model.colleage.SubjectShareInfo;
import com.yoomiito.app.model.my.InviteFriend;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.share.ui.NewInviteShareActivity;
import com.yoomiito.app.utils.YMToast;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class InviteSharePresenter extends BaseActPresenter<NewInviteShareActivity> {

    public InviteSharePresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getInviteADData() {
        YmApi.getYmService()
                .getInviteADSource(1, 100)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<InviteFriend>(handleException()) {
                    @Override
                    public void onSuccess(InviteFriend baseModel) {
                        getV().setInviteFriendData(baseModel);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        getV().setInviteFriendData(null);
//                        YMToast.showText(error.getMsg());
//                        getV().finish();
                    }
                });
    }

    public void getSubjectShareInfo(long id) {
        YmApi.getYmService()
                .getSubjectShareInfo(id)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<SubjectShareInfo>() {
                    @Override
                    public void onSuccess(SubjectShareInfo subjectShareInfo) {
                        getV().setSubjectShareInfo(subjectShareInfo);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        YMToast.showText(error.getMsg());
                        getV().finish();
                    }
                });
    }
}
